// arch/riscv/include/proc.h

#ifndef _PROC_H
#define _PROC_H

#include "ktypes.h"

#define NR_TASKS  (1 + 4) // 用于控制 最大线程数量 （idle 线程 + 31 内核线程）

#define TASK_RUNNING 0 // 为了简化实验，所有的线程都只有一种状态

#define MAX_COUNTER 11 

#define PRIORITY_MIN 1
#define PRIORITY_MAX 10

// proc.h 

typedef unsigned long* pagetable_t;

struct thread_struct {
    uint64 ra;
    uint64 sp;                     
    uint64 s[12];

    uint64 sepc, sstatus, sscratch; 
};

struct thread_info {
    uint64 kernel_sp;
    uint64 user_sp;
};

struct task_struct {
    struct thread_info* thread_info;
    uint64 state;
    uint64 counter;
    uint64 priority;
    uint64 pid;

    struct thread_struct thread;

    pagetable_t pgd_satp;
};

struct pt_regs{
    uint64 sepc;
    uint64 stval;
    uint64 scause;
    uint64 sstatus;
    uint64 x31;
    uint64 x30;
    uint64 x29;
    uint64 x28;
    uint64 x27;
    uint64 x26;
    uint64 x25;
    uint64 x24; 
    uint64 x23;
    uint64 x22;
    uint64 x21;
    uint64 x20;
    uint64 x19;
    uint64 x18;
    uint64 a7;
    uint64 a6;
    uint64 a5;
    uint64 a4;
    uint64 a3;
    uint64 a2;
    uint64 a1;
    uint64 a0;
    uint64 x9;
    uint64 x8;
    uint64 x7;
    uint64 x6;
    uint64 x5;
    uint64 x4;
    uint64 x3;
    uint64 x1; 
    uint64 x2;
};

/* 线程初始化 创建 NR_TASKS 个线程 */
void task_init();

/* 在时钟中断处理中被调用 用于判断是否需要进行调度 */
void do_timer();

/* 调度程序 选择出下一个运行的线程 */
void schedule();

/* 线程切换入口函数*/
void switch_to(struct task_struct* next);

/* dummy funciton: 一个循环程序，循环输出自己的 pid 以及一个自增的局部变量*/
void dummy();


#endif
